package org.playground.booking.dao.impl;

import org.hibernate.query.Query;
import org.playground.booking.dao.IConfigUrlDao;
import org.playground.booking.entity.UrlConfig;
import org.playground.booking.enums.UrlConfigType;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class ConfigUrlDaoImpl extends AbstractDaoImpl<UrlConfig,Long> implements IConfigUrlDao {

    public UrlConfig getUrlByType(UrlConfigType urlConfigType) {
        String hql = "from UrlConfig as conf " +
                "where accountType =: configType";
        Query query = this.getCurrentSession().createQuery(hql);
        query.setParameter("configType",urlConfigType.getType());

        List<UrlConfig> result = query.list();

        return result.size()==0?null:result.get(0);
    }
}
